
define(
	function (require, exports) {

		exports.ready = function (hashCode, data, cite) {

			yufp.custom.vue({
				el: cite.el,
				data: function () {
					var _this = this;
					return {
						searchFormdata: {},
						queryObjUserFormdata: {},
						addFnButton: !yufp.session.checkCtrl('addFn'),
						updateFnButton: !yufp.session.checkCtrl('updateFn'),
						deleteFnButton: !yufp.session.checkCtrl('deleteFn'),
						dataUrl: 'api/use/plats/appright/queryAppRightList',
						objDataUserUrl: "api/adminsmuser/querypage",
						saveBtnShow: true,
						cancelBtnShow: true,
						formdata: {},
						isReadOnly: false,
						saveDisabled: false,
						async: false,
						appList: [],
						height: yufp.frame.size().height,
						dialogVisible: false,
						viewTitleArrry: ['应用系统授权新增', '应用系统授权修改', '应用系统授权查看'],
						viewTitle: '',
						addFlag: true,
						objectUserTabVisible: false,
						baseParam: { condition: { orgId: yufp.session.org.id } },
						queryObjUserFields: [{ placeholder: '登录代码/姓名/员工号', field: 'userInfo', type: 'input' }],
						queryFields: [
							{ placeholder: '应用系统代码', field: 'appCode', type: 'input' },
							{ placeholder: '应用系统名称', field: 'appName', type: 'input' },
							{ placeholder: '用户ID', field: 'userId', type: 'input', disabled: false },
							{ placeholder: '用户名称', field: 'userName', type: 'input', disabled: false },

						],
						queryButtons: [
							{
								label: '搜索', op: 'submit', type: 'primary', icon: "search", click: function (model, valid) {

									_this.reloadData();
								}
							},
							{ label: '重置', op: 'reset', type: 'primary', icon: 'yx-loop2' }
						],
						queryObjUserButtons: [
							{
								label: '搜索', op: 'submit', type: 'primary', icon: "search", click: function (model, valid) {

									model.orgId = yufp.session.org.id;


									_this.$refs.refObjUserTable.remoteData({ condition: model });
								}
							},
							{
								label: '确认', op: 'submit', type: 'primary', icon: 'check', click: function () {
									let selectDatas = _this.$refs.refObjUserTable.selections;
									for (var i = 0; i < selectDatas.length; i++) {
										_this.formdata.userId = selectDatas[i].loginCode;
										_this.formdata.userName = selectDatas[i].userName;
									}
									if (_this.$refs.refObjUserTable.selections != null)
										_this.$refs.refObjUserTable.selections.splice(0);
									_this.objectUserTabVisible = false;
								}
							}
						]
					};
				},
				methods: {

					reloadData: function () {
						var _this = this;
						// var param = this.$refs.queryObjUserRef.fm;
						var param = {};
						param.orgId = yufp.session.org.id
						_this.$refs.refTable.remoteData({ condition: JSON.stringify(param) });
					},

					searchUser: function () {
						var _this = this;
						_this.objectUserTabVisible = true;
						_this.$nextTick(function () {
							_this.$refs.refObjUserTable.remoteData({});
						});

						//_this.$refs.queryObjUserRef.reset();
					},



					/**
					 * 取消
					 */
					cancelFn: function () {
						var _this = this;
						_this.clearAllFn();
						_this.dialogVisible = false;
					},
					/**
					 * 保存
					 */
					saveFn: function () {
						var _this = this;
						var validate = false;
						_this.$refs.refForm.validate(function (valid) {
							validate = valid;
						});
						if (!validate) {
							return;
						}
						var paramObj = _this.$refs.refForm.formdata;

						for (let i = 0; i < _this.appList.length; i++) {
							if (paramObj.appCode === _this.appList[i].key) {
								paramObj.appName = _this.appList[i].value;
								break;
							}
						}

						let url = "";
						if (_this.addFlag) {
							url = 'api/use/plats/appright/add';
						} else {
							url = 'api/use/plats/appright/update';
						}

						yufp.service.request({
							method: 'POST',
							url: url,
							data: paramObj,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message({ message: response.message, type: "warning" });
								} else {
									_this.reloadData();
									_this.$message('操作成功');
									_this.dialogVisible = false;
								}

							}
						});

					},
					/**
					 * 控制保存按钮、xdialog、表单的状态
					 * @param viewType 表单类型
					 * @param editable 可编辑,默认false
					 */
					switchStatus: function (viewType, editable) {
						var _this = this;
						_this.viewType = viewType;
						_this.dialogVisible = true;
						_this.saveBtnShow = editable;
						_this.cancelBtnShow = editable;
					},
					/**
					 * 新增
					 */
					addFn: function () {
						var _this = this;

						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/appright/queryWftAppList",
							data: {},
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message(response.message);
								} else {
									_this.appList.splice(0);

									if (response.data.length > 0) {
										for (let i = 0; i < response.data.length; i++) {
											_this.appList.push({ key: response.data[i].appCode, value: response.data[i].appName })
										}

									}
								}
								_this.dialogVisible = true;
								_this.viewTitle = _this.viewTitleArrry[0];
								_this.addFlag = true;
								_this.saveDisabled = false;
								_this.$nextTick(function () {
									_this.viewTitle = _this.viewTitleArrry[0];
									_this.clearAllFn();
								});

							}
						});


					},

					clearAllFn: function () {
						var _this = this;
						_this.$refs.refForm.resetFields();
						_this.isReadOnly = false;
					},

					modifyFn: function () {
						var _this = this;
						if (_this.$refs.refTable.selections.length != 1) {
							_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
							return;
						}
						_this.viewTitle = _this.viewTitleArrry[1];
						_this.dialogVisible = true;
						_this.addFlag = false;
						_this.saveDisabled = false;
						_this.isReadOnly = true;
						_this.$nextTick(function () {
							_this.clearAllFn();
							_this.formdata.appCode = _this.$refs.refTable.selections[0].appCode;
							_this.formdata.userId = _this.$refs.refTable.selections[0].userId;
							_this.formdata.userName = _this.$refs.refTable.selections[0].userName;
							_this.formdata.remark = _this.$refs.refTable.selections[0].remark;

						})
					},




					viewFn: function (obj) {

						var _this = this;

						_this.viewTitle = _this.viewTitleArrry[2];
						_this.dialogVisible = true;
						_this.addFlag = false;
						_this.saveDisabled = true;
						_this.$nextTick(function () {
							_this.clearAllFn();
							_this.formdata.appCode = obj.appCode;
							_this.formdata.userId = obj.userId;
							_this.formdata.userName = obj.userName;
							_this.formdata.remark = obj.remark;

						})

					},

					queryWftApp: function () {

						var _this = this;

						yufp.service.request({
							method: 'GET',
							url: "api/use/plats/appright/queryWftAppList",
							data: {},
							async: false,
							callback: function (code, message, response) {
								if (response.code != 0) {
									_this.$message(response.message);
								} else {
									_this.appList.splice(0);

									if (response.data.length > 0) {
										for (let i = 0; i < response.data.length; i++) {
											_this.appList.push({ key: response.data[i].appCode, value: response.data[i].appName })
										}

									}
								}

							}
						});

					},



					/**
					 * 删除
					 */
					deleteFN: function () {
						var _this = this;
						var selections = _this.$refs.refTable.selections;
						if (selections.length != 1) {
							_this.$message({ message: '请先选择一条记录', type: 'warning', duration: 6000 });
							return;
						}
						_this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning', duration: 6000,
							center: true,
							callback: function (action) {
								if (action === 'confirm') {
									yufp.service.request({
										method: 'DELETE',
										url: 'api/use/plats/appright/delete',
										data: _this.$refs.refTable.selections[0],
										callback: function (code, message, response) {
											if (response.code == 0) {
												_this.reloadData();
												_this.$message('操作成功');
											} else {
												_this.$message(response.message);
											}
										}
									});
								}
							}
						});
					},


				},
				mounted: function () {
					this.queryWftApp();
				},
				beforeMount: function () {
					this.queryWftApp();
				},
			});
		};
	});